package com.example.demo.repository;


import com.example.demo.model.Assignment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AssignmentRepository extends JpaRepository<Assignment, Long> {
    List<Assignment> findByCourseId(Long courseId);

    @Query("SELECT a FROM Assignment a WHERE a.course.id = :courseId AND " +
            "(SELECT COUNT(sa) FROM StudentAssignment sa WHERE sa.assignment.id = a.id AND sa.student.id = :studentId) > 0")
    List<Assignment> findByCourseIdAndStudentId(Long courseId, Long studentId);

    boolean existsByIdAndCourseId(Long assignmentId, Long courseId);
}